const path = require("path")
const fs = require("fs-extra")

module.exports = {


    // 启动
    async start(url, saveDir = __dirname + "/data") {

        // 创建页面
        const page = await this.context.newPage()

        // 监听请求
        page.on('requestfinished', request => this.onRequestFinished(request, saveDir))

        // 打开url
        await page.goto(url)

    },

    async onRequestFinished(request, saveDir) {

        // 创建请求信息
        const requestinfo = await this.createRequestInfo(request)

        // 保存请求信息
        await this.saveRequestInfo(requestinfo, {
            saveDir: saveDir,
            resourceType: ["xhr", "fetch"],
            onlyJson: true
        })
    }

}